package pl.easyshop.core.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import pl.easyshop.core.model.enums.UserAccountType;

/**
 * User data model.
 * 
 * @author Pawel Witkowski
 */
@Entity
@Table(name="TBL_USER")
public class UserModel extends AbstractBaseModel {
	
	/** Unique serialization identifier. */
	private static final long serialVersionUID = -8715363484226193916L;

	/** User name field is use during login process. */
	@Column(name="username", nullable=false, length=64)
	private String username;
	
	/** Password. */
	@Column(name="password", nullable=false, length=128)
	private String password;
	
	/** First name. */
	@Column(name="first_name", length=255)
	private String firstName;
	
	/** Last name. */
	@Column(name="last_name", length=255)
	private String lastName;
	
	/** E-mail address. */
	@Column(name="email", nullable=false, length=255)
	private String email;
	
	/** Active user account. */
	@Column(name="is_enabled", nullable=false)
	private boolean enabled;

	/** User account type. */
	@Enumerated(EnumType.STRING)
	@Column(name="account_type", length=32)
	private UserAccountType accountType;
	
	/** Create account date. */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="created_date")
	private Date createDate;
	
	/** Last modified date. */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="modified_date")
	private Date modifiedDate;
	
	/** Field value <code>true</code> means user is currently logged in system. */
	@Column(name="is_online")
	private boolean online;
	
	/** Last login date. */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="last_login_date")
	private Date lastLoginDate;

	/** List of user groups. */
	@ManyToMany(mappedBy = "members", cascade={CascadeType.PERSIST, CascadeType.MERGE})
	@LazyCollection(LazyCollectionOption.FALSE)
	private Set<UserGroupModel> groups = new HashSet<UserGroupModel>();	
	
	/**
	 * Get username property value.
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * Set username property value.
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * Get password property value.
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Set password property value.
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * Get firstName property value.
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Set firstName property value.
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Get lastName property value.
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Set lastName property value.
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Get email property value.
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Set email property value.
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Get enabled property value.
	 * @return the enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * Set enabled property value.
	 * @param enabled the enabled to set
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * Get accountType property value.
	 * @return the accountType
	 */
	public UserAccountType getAccountType() {
		return accountType;
	}

	/**
	 * Set accountType property value.
	 * @param accountType the accountType to set
	 */
	public void setAccountType(UserAccountType accountType) {
		this.accountType = accountType;
	}

	/**
	 * Get createDate property value.
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}

	/**
	 * Set createDate property value.
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	/**
	 * Get modifiedDate property value.
	 * @return the modifiedDate
	 */
	public Date getModifiedDate() {
		return modifiedDate;
	}

	/**
	 * Set modifiedDate property value.
	 * @param modifiedDate the modifiedDate to set
	 */
	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	/**
	 * Get online property value.
	 * @return the online
	 */
	public boolean isOnline() {
		return online;
	}

	/**
	 * Set online property value.
	 * @param online the online to set
	 */
	public void setOnline(boolean online) {
		this.online = online;
	}

	/**
	 * Get lastLoginDate property value.
	 * @return the lastLoginDate
	 */
	public Date getLastLoginDate() {
		return lastLoginDate;
	}

	/**
	 * Set lastLoginDate property value.
	 * @param lastLoginDate the lastLoginDate to set
	 */
	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	/**
	 * Get groups property value.
	 * @return the groups
	 */
	public Set<UserGroupModel> getGroups() {
		return groups;
	}

	/**
	 * Set groups property value.
	 * @param groups the groups to set
	 */
	public void setGroups(Set<UserGroupModel> groups) {
		this.groups = groups;
	}

	
}
